1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
| #pragma warning(disable:4996) #include<iostream> #include<vector> #include<cmath> #include<queue> #include<functional> #define INF 999999 using namespace std;
int n, m;
int tetriminoX[5][4] = { { 0,0,0,0 },{ 0,1,1,1 },{ 0,1,1,2 },{ 0,0,0,1 },{ 0,0,1,1 } }; int tetriminoY[5][4] = { { 0,1,2,3 },{ 0,0,1,2 },{ 0,0,1,1 },{ 0,1,2,1 },{ 0,1,0,1 } }; int map[500][500];
void rotate(int& x, int& y) { int temp = x; x = y; y = -temp; }
void xSymet(int& y) { y = -y; }
int isOk(int s, int e, int x[4], int y[4]) { for (int i = 0; i < 4; i++) { if (0 <= s + x[i] && s + x[i] < n && 0 <= e + y[i] && e + y[i] < m) { } else return false; }
return true; }
int main() {
scanf("%d %d", &n, &m);
for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) scanf("%d", &map[i][j]); }
int max = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { for (int k = 0; k < 5; k++) { for (int c = 0; c < 2; c++) { for (int l = 0; l < 4; l++) {
if (isOk(i, j, tetriminoX[k], tetriminoY[k])) { int sum = 0; for (int o = 0; o < 4; o++) { sum += map[i + tetriminoX[k][o]][j + tetriminoY[k][o]];
} if (max < sum) max = sum; } for (int z = 0; z < 4; z++) rotate(tetriminoX[k][z], tetriminoY[k][z]); }
for (int i = 0; i < 5; i++) { for (int j = 0; j < 4; j++) xSymet(tetriminoY[i][j]); }
} } } }
printf("%d\n", max); }
|